﻿// Control20Dlg_1.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "Control20Dlg_1.h"
#include "afxdialogex.h"


// CControl20Dlg_1 对话框

IMPLEMENT_DYNAMIC(CControl20Dlg_1, CDialogEx)

CControl20Dlg_1::CControl20Dlg_1(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_CONTROL_20, pParent)
{

}

CControl20Dlg_1::~CControl20Dlg_1()
{
}

void CControl20Dlg_1::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT2, m_editX);
	DDX_Control(pDX, IDC_EDIT3, m_editY);
	DDX_Control(pDX, IDC_EDIT4, m_editZ);
	DDX_Control(pDX, IDC_EDIT1, m_editStep);
	DDX_Control(pDX, IDC_COMBO1, m_combPosNo);
}


BEGIN_MESSAGE_MAP(CControl20Dlg_1, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON34, &CControl20Dlg_1::OnBnClickedButton34)
	ON_BN_CLICKED(IDC_BUTTON6, &CControl20Dlg_1::OnBnClickedButton6)
	ON_BN_CLICKED(IDC_BUTTON4, &CControl20Dlg_1::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON5, &CControl20Dlg_1::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON35, &CControl20Dlg_1::OnBnClickedButton35)
	ON_BN_CLICKED(IDC_BUTTON37, &CControl20Dlg_1::OnBnClickedButton37)
	ON_BN_CLICKED(IDC_BUTTON33, &CControl20Dlg_1::OnBnClickedButton33)
	ON_BN_CLICKED(IDC_BUTTON10, &CControl20Dlg_1::OnBnClickedButton10)
	ON_BN_CLICKED(IDC_BUTTON26, &CControl20Dlg_1::OnBnClickedButton26)
	ON_BN_CLICKED(IDC_BUTTON27, &CControl20Dlg_1::OnBnClickedButton27)
	ON_BN_CLICKED(IDC_BUTTON28, &CControl20Dlg_1::OnBnClickedButton28)
	ON_BN_CLICKED(IDC_BUTTON29, &CControl20Dlg_1::OnBnClickedButton29)
	ON_BN_CLICKED(IDC_BUTTON30, &CControl20Dlg_1::OnBnClickedButton30)
	ON_BN_CLICKED(IDC_BUTTON31, &CControl20Dlg_1::OnBnClickedButton31)
	ON_BN_CLICKED(IDC_BUTTON32, &CControl20Dlg_1::OnBnClickedButton32)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON24, &CControl20Dlg_1::OnBnClickedButton24)
	ON_BN_CLICKED(IDC_BUTTON25, &CControl20Dlg_1::OnBnClickedButton25)
	ON_BN_CLICKED(IDC_BUTTON8, &CControl20Dlg_1::OnBnClickedButton8)
	ON_BN_CLICKED(IDC_BUTTON9, &CControl20Dlg_1::OnBnClickedButton9)
	ON_BN_CLICKED(IDC_BUTTON12, &CControl20Dlg_1::OnBnClickedButton12)
	ON_BN_CLICKED(IDC_BUTTON23, &CControl20Dlg_1::OnBnClickedButton23)
	ON_BN_CLICKED(IDC_BUTTON1, &CControl20Dlg_1::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON7, &CControl20Dlg_1::OnBnClickedButton7)
	ON_BN_CLICKED(IDC_BUTTON38, &CControl20Dlg_1::OnBnClickedButton38)
	ON_BN_CLICKED(IDC_CHECK3, &CControl20Dlg_1::OnBnClickedCheck3)
	ON_BN_CLICKED(IDC_CHECK5, &CControl20Dlg_1::OnBnClickedCheck5)
	ON_BN_CLICKED(IDC_CHECK6, &CControl20Dlg_1::OnBnClickedCheck6)
	ON_BN_CLICKED(IDC_CHECK10, &CControl20Dlg_1::OnBnClickedCheck10)
	ON_BN_CLICKED(IDC_CHECK11, &CControl20Dlg_1::OnBnClickedCheck11)
	ON_BN_CLICKED(IDC_CHECK14, &CControl20Dlg_1::OnBnClickedCheck14)
	ON_BN_CLICKED(IDC_CHECK15, &CControl20Dlg_1::OnBnClickedCheck15)
	ON_BN_CLICKED(IDC_CHECK16, &CControl20Dlg_1::OnBnClickedCheck16)
	ON_BN_CLICKED(IDC_BUTTON40, &CControl20Dlg_1::OnBnClickedButton40)
END_MESSAGE_MAP()


// CControl20Dlg_1 消息处理程序


void CControl20Dlg_1::OnCancel()
{
	KillTimer(TIMER_ID_AXIS_STATUS_2);
	CDialogEx::OnCancel();
}


BOOL CControl20Dlg_1::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	m_combPosNo.ResetContent();
	m_combPosNo.AddString(L"0:待机位");
	m_combPosNo.AddString(L"1:模组Plasma起点");
	m_combPosNo.AddString(L"2:镜头Plasma起点");
	m_combPosNo.AddString(L"3:污点测试位");
	m_combPosNo.SetCurSel(0);
	SetTimer(TIMER_ID_AXIS_STATUS_2, 500, NULL);

	return TRUE;
}


void CControl20Dlg_1::OnBnClickedButton34()
{
	if (gSystemMgr.Y09 == OFF) {
		gSystemMgr.m_cIo.SetOutputIo(9, ON);
	}
	else {
		gSystemMgr.m_cIo.SetOutputIo(9, OFF);
	}
}


void CControl20Dlg_1::OnBnClickedButton6()
{
	if (gSystemMgr.Y10 == OFF) {
		gSystemMgr.m_cIo.SetOutputIo(10, ON);
	}
	else {
		gSystemMgr.m_cIo.SetOutputIo(10, OFF);
	}
}


void CControl20Dlg_1::OnBnClickedButton4()
{
	gSystemMgr.m_cIo.SetOutputIo(11, ON);
	gSystemMgr.m_cIo.SetOutputIo(12, OFF);
}


void CControl20Dlg_1::OnBnClickedButton5()
{
	gSystemMgr.m_cIo.SetOutputIo(11, OFF);
	gSystemMgr.m_cIo.SetOutputIo(12, ON);
}


void CControl20Dlg_1::OnBnClickedButton35()
{
	gSystemMgr.m_cIo.SetOutputIo(13, ON);
	gSystemMgr.m_cIo.SetOutputIo(14, OFF);
}


void CControl20Dlg_1::OnBnClickedButton37()
{
	gSystemMgr.m_cIo.SetOutputIo(14, ON);
	gSystemMgr.m_cIo.SetOutputIo(13, OFF);
}


void CControl20Dlg_1::OnBnClickedButton33()
{
	if (gSystemMgr.Y39 == OFF) {
		gSystemMgr.m_cIo.SetOutputIo(39, OFF);
	}
	else {
		gSystemMgr.m_cIo.SetOutputIo(39, OFF);
	}
}



void CControl20Dlg_1::OnBnClickedButton10()
{
	gSystemMgr.m_cIo.SetOutputIo(15, ON);
	gSystemMgr.m_cIo.SetOutputIo(16, OFF);
}


void CControl20Dlg_1::OnBnClickedButton26()
{
	gSystemMgr.m_cIo.SetOutputIo(16, ON);
	gSystemMgr.m_cIo.SetOutputIo(15, OFF);
}


void CControl20Dlg_1::OnBnClickedButton27()
{
	gSystemMgr.m_cIo.SetOutputIo(19, ON);
	gSystemMgr.m_cIo.SetOutputIo(20, OFF);
}


void CControl20Dlg_1::OnBnClickedButton28()
{
	gSystemMgr.m_cIo.SetOutputIo(20, ON);
	gSystemMgr.m_cIo.SetOutputIo(19, OFF);
}


void CControl20Dlg_1::OnBnClickedButton29()
{
	gSystemMgr.m_cIo.SetOutputIo(17, ON);
	gSystemMgr.m_cIo.SetOutputIo(18, OFF);
}


void CControl20Dlg_1::OnBnClickedButton30()
{
	gSystemMgr.m_cIo.SetOutputIo(18, ON);
	gSystemMgr.m_cIo.SetOutputIo(17, OFF);
}


void CControl20Dlg_1::OnBnClickedButton31()
{
	gSystemMgr.m_cIo.SetOutputIo(21, ON);
	gSystemMgr.m_cIo.SetOutputIo(22, OFF);
}


void CControl20Dlg_1::OnBnClickedButton32()
{
	gSystemMgr.m_cIo.SetOutputIo(22, ON);
	gSystemMgr.m_cIo.SetOutputIo(21, OFF);
}


void CControl20Dlg_1::OnTimer(UINT_PTR nIDEvent)
{
	if (nIDEvent == TIMER_ID_AXIS_STATUS_2)
	{
		double nDis = gSystemMgr.m_vCMotor[MOTOR_X1].m_nCurPositon;
		CString cstr;
		cstr.Format(L"%.1f", nDis);
		m_editX.SetWindowTextW(cstr);
		nDis = gSystemMgr.m_vCMotor[MOTOR_Y1].m_nCurPositon;
		cstr.Format(L"%.1f", nDis);
		m_editY.SetWindowTextW(cstr);
		nDis = gSystemMgr.m_vCMotor[MOTOR_Z1].m_nCurPositon;
		cstr.Format(L"%.1f", nDis);
		m_editZ.SetWindowTextW(cstr);
	}
	CDialogEx::OnTimer(nIDEvent);
}


void CControl20Dlg_1::OnBnClickedButton24()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_X1].m_sAxisSetting.m_dTargetPos = _ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_X1].MotorMoveStep();
}


void CControl20Dlg_1::OnBnClickedButton25()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_X1].m_sAxisSetting.m_dTargetPos = -_ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_X1].MotorMoveStep();
}


void CControl20Dlg_1::OnBnClickedButton8()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Y1].m_sAxisSetting.m_dTargetPos = _ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Y1].MotorMoveStep();
}


void CControl20Dlg_1::OnBnClickedButton9()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Y1].m_sAxisSetting.m_dTargetPos = -_ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Y1].MotorMoveStep();
}


void CControl20Dlg_1::OnBnClickedButton12()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Z1].m_sAxisSetting.m_dTargetPos = _ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Z1].MotorMoveStep();
}


void CControl20Dlg_1::OnBnClickedButton23()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Z1].m_sAxisSetting.m_dTargetPos = -_ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Z1].MotorMoveStep();
}


void CControl20Dlg_1::OnBnClickedButton1()
{
	gSystemMgr.m_vCMotor[MOTOR_X1].StopMove();
	gSystemMgr.m_vCMotor[MOTOR_Y1].StopMove();
	gSystemMgr.m_vCMotor[MOTOR_Z1].StopMove();
}


void CControl20Dlg_1::OnBnClickedButton7()
{
	int n;
	n = m_combPosNo.GetCurSel();
	gSystemMgr.m_nButtonValue = 235 + n;
}


void CControl20Dlg_1::OnBnClickedButton38()
{
	gSystemMgr.m_nButtonValue = 231;
}


void CControl20Dlg_1::OnBnClickedCheck3()
{
	CString cstr;
	CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK3);
	int nFlag = pCheckBox->GetCheck();
	if (nFlag == BST_CHECKED)
	{
		gSystemMgr.m_cIo.SetOutputIo(9, ON);
	}
	else
	{
		gSystemMgr.m_cIo.SetOutputIo(9, OFF);
	}
}


void CControl20Dlg_1::OnBnClickedCheck5()
{
	CString cstr;
	CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK5);
	int nFlag = pCheckBox->GetCheck();
	if (nFlag == BST_CHECKED)
	{
		gSystemMgr.m_cIo.SetOutputIo(10, ON);
	}
	else
	{
		gSystemMgr.m_cIo.SetOutputIo(10, OFF);
	}
}


void CControl20Dlg_1::OnBnClickedCheck6()
{
	CString cstr;
	CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK6);
	int nFlag = pCheckBox->GetCheck();
	if (nFlag == BST_CHECKED)
	{
		gSystemMgr.m_cIo.SetOutputIo(11, ON);
		gSystemMgr.m_cIo.SetOutputIo(12, OFF);
	}
	else
	{
		gSystemMgr.m_cIo.SetOutputIo(12, ON);
		gSystemMgr.m_cIo.SetOutputIo(11, OFF);
	}
}


void CControl20Dlg_1::OnBnClickedCheck10()
{
	CString cstr;
	CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK10);
	int nFlag = pCheckBox->GetCheck();
	if (nFlag == BST_CHECKED)
	{
		gSystemMgr.m_cIo.SetOutputIo(13, ON);
		gSystemMgr.m_cIo.SetOutputIo(14, OFF);
	}
	else
	{
		gSystemMgr.m_cIo.SetOutputIo(14, ON);
		gSystemMgr.m_cIo.SetOutputIo(13, OFF);
	}
}


void CControl20Dlg_1::OnBnClickedCheck11()
{
	CString cstr;
	CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK11);
	int nFlag = pCheckBox->GetCheck();
	if (nFlag == BST_CHECKED)
	{
		gSystemMgr.m_cIo.SetOutputIo(51, ON);
		gSystemMgr.m_cIo.SetOutputIo(52, OFF);
	}
	else
	{
		gSystemMgr.m_cIo.SetOutputIo(52, ON);
		gSystemMgr.m_cIo.SetOutputIo(51, OFF);
	}
}


void CControl20Dlg_1::OnBnClickedCheck14()
{
	CString cstr;
	CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK14);
	int nFlag = pCheckBox->GetCheck();
	if (nFlag == BST_CHECKED)
	{
		gSystemMgr.m_cIo.SetOutputIo(21, ON);
		gSystemMgr.m_cIo.SetOutputIo(22, OFF);
	}
	else
	{
		gSystemMgr.m_cIo.SetOutputIo(22, ON);
		gSystemMgr.m_cIo.SetOutputIo(21, OFF);
	}
}


void CControl20Dlg_1::OnBnClickedCheck15()
{
	CString cstr;
	CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK15);
	int nFlag = pCheckBox->GetCheck();
	if (nFlag == BST_CHECKED)
	{
		gSystemMgr.m_cIo.SetOutputIo(17, ON);
		gSystemMgr.m_cIo.SetOutputIo(18, OFF);
	}
	else
	{
		gSystemMgr.m_cIo.SetOutputIo(18, ON);
		gSystemMgr.m_cIo.SetOutputIo(17, OFF);
	}
}


void CControl20Dlg_1::OnBnClickedCheck16()
{
	CString cstr;
	CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK16);
	int nFlag = pCheckBox->GetCheck();
	if (nFlag == BST_CHECKED)
	{
		gSystemMgr.m_cIo.SetOutputIo(19, ON);
		gSystemMgr.m_cIo.SetOutputIo(20, OFF);
	}
	else
	{
		gSystemMgr.m_cIo.SetOutputIo(20, ON);
		gSystemMgr.m_cIo.SetOutputIo(19, OFF);
	}
}


void CControl20Dlg_1::OnBnClickedButton40()
{
	gSystemMgr.m_nButtonValue = 232;
}
